package com.hpsk.shopsatoken.model.satoken.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONUtil;
import com.hpsk.common.RespResult;
import com.hpsk.common.RespUtils;
import com.hpsk.shopsatoken.model.user.dto.LoginParamDto;
import com.hpsk.shopsatoken.model.user.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangwang2832511019
 */
@RestController
@RequestMapping("/saToken")
@Tag(name = "satoken控制器")
@Slf4j
@AllArgsConstructor(onConstructor_ = @__(@Autowired))
public class TestloginController {

    private final IUserService iUserService;
    @GetMapping("/login")
    @Operation(description = "登录",  summary = "登录")
    public RespResult<SaTokenInfo> login(@ParameterObject LoginParamDto loginParamDto) {
        log.info("loginParamDto:{}", JSONUtil.toJsonStr(loginParamDto));
        SaTokenInfo login = iUserService.login(loginParamDto);
        // 第3步，返回给前端
        return RespUtils.ok(login);
    }
}
